package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.Member;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

import java.util.List;

public interface MemberDao {

    public List<Member> findAll();

    @Select("<script>select * from t_member <if test=\"queryString!=null and queryString!=''\">where code=#{queryString} or name=#{queryString}</if></script>")
    public Page<Member> selectByCondition(@Param("queryString") String queryString);

    @Insert("insert into t_member(id,fileNumber,name,sex,idCard,phoneNumber,regTime,password,email,birthday,remark) values(#{id},#{fileNumber},#{name},#{sex},#{idCard},#{phoneNumber},#{regTime},#{password},#{email},#{birthday},#{remark})")
    @SelectKey(statement = "select last_insert_id()", before = false, keyProperty = "id", resultType = Integer.class, keyColumn = "id")
    public void add(Member member);

    public void deleteById(Integer id);

    @Select("select * from t_member where id=#{id}")
    public Member findById(Integer id);

    @Select("select * from t_member where phoneNumber=#{telephone}")
    public Member findByTelephone(String phoneNumber);

    public void edit(Member member);

    @Select("select count(id) from t_member where regTime <= #{date}")
    public Integer findMemberCountBeforeDate(String date);

    @Select("select count(id) from t_member where regTime = #{date}")
    public Integer findMemberCountByDate(String date);

    @Select("select count(id) from t_member where regTime >= #{date}")
    public Integer findMemberCountAfterDate(String date);

    @Select("select count(id) from t_member")
    public Integer findMemberTotalCount();
}
